<?php
session_start();
include './c/config.php';
$url='http://127.0.0.1:8031/api/wx/access_token?appId='.$appId.'&code='.$_GET['code'];
$getData=json_decode(file_get_contents($url), true);
$openid=$getData['data']['openid'];
 
echo $openid;


$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
$_SESSION['openid']=$openid;
$sql="select id from users where openid='".$openid."'  limit 0,1 ";
$query = $mysqli->query($sql);
if($query->num_rows>0){
}else{
    $sql = "insert into users(openid,nickname,createtime) values ('".$openid."','测试','".date("Y-m-d H:i:s")."' )";
   echo $sql;
    $mysqli->query($sql);
}
 
exit;

$redirect_uri = urlencode('http://climb-game.51wom.com/c.php');
$api_userinfo ='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appId.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
header('Location: '.$api_userinfo);
exit;